package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.CustomerTraceHistory;
import cn.wolfcode.crm.domain.Employee;
import cn.wolfcode.crm.domain.Role;
import cn.wolfcode.crm.domain.SystemDictionaryItem;
import cn.wolfcode.crm.qo.QueryObject;
import cn.wolfcode.crm.service.ICustomerTraceHistoryService;
import cn.wolfcode.crm.service.IEmployeeService;
import cn.wolfcode.crm.service.ISystemDictionaryItemService;
import cn.wolfcode.crm.util.JsonResult;
import com.github.pagehelper.PageInfo;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/customerTraceHistory")
public class CustomerTraceHistoryController {

    @Autowired
    private ICustomerTraceHistoryService customerTraceHistoryService;

    // 客户跟进历史新增或修改
    @RequestMapping("/saveOrUpdate")
    @ResponseBody
    @RequiresPermissions(value={"customerTraceHistory:saveOrUpdate","客户跟进历史新增或修改"},logical= Logical.OR)
    public JsonResult saveOrUpdate(CustomerTraceHistory customerTraceHistory){
        try{
            if(customerTraceHistory.getId() != null){
                customerTraceHistoryService.update(customerTraceHistory);
            }else {
                customerTraceHistoryService.save(customerTraceHistory);
            }
        }catch (Exception e){
            e.printStackTrace();
            return new JsonResult(false,"操作失败");
        }
        return new JsonResult(true,"操作成功!!!"); // localhost/customerTraceHistory/list.do
    }

    // 查询所有客户跟进历史数据
    @RequestMapping("/potentialList")
    @RequiresPermissions(value={"customerTraceHistory:potentialList","客户跟进历史列表"},logical= Logical.OR)
    public String list(Model model, @ModelAttribute("qo")QueryObject qo){

        PageInfo query = customerTraceHistoryService.query(qo);
        model.addAttribute("pageResult", query);
        return "customerTraceHistory/potentialList";
    }
}
